package com.itsite.guider.demo.demo

import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.itsite.guider.demo.R
import com.water.guider.BaseViewHolder
import com.water.guider.Guide
import com.water.guider.Guider
import com.water.guider.GuiderView
import com.water.guider.highlight.Highlight.oval
import com.water.guider.position.Position

class SimpleActivity : AppCompatActivity(), View.OnClickListener {
    private var textView: TextView? = null
    private var imageView: ImageView? = null
    private var button: Button? = null
    private var guider: Guider? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_next)
        initView()
        initGuider()
    }

    private fun initView() {
        textView = findViewById<View>(R.id.textView) as TextView
        imageView = findViewById<View>(R.id.imageView) as ImageView
        button = findViewById<View>(R.id.button) as Button
        textView!!.setOnClickListener(this)
        imageView!!.setOnClickListener(this)
        button!!.setOnClickListener(this)
    }

    private fun initGuider() {
        guider = Guider.Builder()
            .setAnchor(this)
            .addGuide(Guide.Builder()
                .setPoint(textView!!)
                .setPosition(Position.bottomLeft())
                .setView(R.layout.guide_0)
                .build())
            .addGuide(Guide.Builder()
                .setPoint(imageView!!)
                .setPosition(Position.bottomRight())
                .setView(R.layout.guide_0)
                .build()
            )
            .addGuide(Guide.Builder()
                .setPoint(button!!)
                .setPosition(Position.top())
                .setHighlight(oval())
                .setView(R.layout.guide_1)
                .build()
            )
            .show()
    }

    override fun onClick(v: View) {
        initGuider()
    }

    override fun onBackPressed() {
        if (guider!!.isVisible) {
            guider!!.dismiss()
        } else {
            super.onBackPressed()
        }
    }

    companion object {
        private val TAG = SimpleActivity::class.java.simpleName
    }
}